package logic

import (
	"context"
	"month2/C/rpc_C/order"

	"month2/C/api_C/internal/svc"
	"month2/C/api_C/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SmsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SmsLogic {
	return &SmsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SmsLogic) Sms(req *types.SmsRequest) (resp *types.Response, err error) {
	sms, err := l.svcCtx.CRpc.Sms(l.ctx, &order.SmsRequest{
		Tel:    req.Tel,
		Source: req.Source,
	})
	if err != nil {
		return &types.Response{
			Msg:  "验证码发送失败",
			Data: nil,
			Code: 500,
		}, nil
	}
	return &types.Response{
		Msg:  "验证码发送成功",
		Data: sms,
		Code: 200,
	}, nil
}
